package com.pan.basic;

import lombok.Getter;
import lombok.Setter;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * @author Administrator
 * @date 2023/11/3
 * @description
 **/
public class InnerClass {

    @Getter
    @Setter
    class Recaculate {

        //计价数量
        private BigDecimal extendPriceQty        ;

        //原币含税价格
        private BigDecimal extendOriTaxPrice     ;
        //原币含税总额
        private BigDecimal extendOriSum          ;
        //原币税额
        private BigDecimal extendOriTax          ;

        //税率
        private BigDecimal extendTaxRate         ;

        //原币不含税价格
        private BigDecimal extendOriTaxFreePrice ;
        //原币不含税总额
        private BigDecimal extendOriTaxFreeSum   ;

        //汇率默认为1
        private BigDecimal exchRate = BigDecimal.ONE;

        //本币价格
        private BigDecimal extendNatTaxPrice     ;
        //本币总额
        private BigDecimal extendNatSum          ;
        //本币税额
        private BigDecimal extendNatTax          ;
        //本币不含税价格
        private BigDecimal extendNatTaxFreePrice ;
        //本币不含税总额
        private BigDecimal extendNatTaxFreeSum   ;



        Recaculate(BigDecimal extendPriceQty, BigDecimal extendOriTaxPrice,BigDecimal extendOriTaxFreePrice){

            this.extendOriTaxPrice = extendOriTaxPrice;
            this.extendPriceQty = extendPriceQty;
            this.extendOriTaxFreePrice = extendOriTaxFreePrice;

            this.extendOriSum = extendOriTaxPrice.multiply(extendPriceQty);
            this.extendOriTaxFreeSum = extendOriTaxFreePrice.multiply(extendPriceQty);
            this.extendOriTax = this.extendOriSum.subtract(extendOriTaxFreeSum);

            this.transOri2NatAndSet(this,BigDecimal.ONE);

        }


        public Recaculate transOri2NatAndSet(Recaculate oriRecaculate,BigDecimal exchRate){


            oriRecaculate.setExtendNatTaxPrice(oriRecaculate.getExtendOriTaxPrice().multiply(exchRate));
            oriRecaculate.setExtendNatTaxFreePrice(oriRecaculate.getExtendOriTaxFreePrice().multiply(exchRate));
            oriRecaculate.setExtendNatSum(oriRecaculate.getExtendOriSum().multiply(exchRate));
            oriRecaculate.setExtendNatTaxFreeSum(oriRecaculate.getExtendOriTaxFreeSum().multiply(exchRate));
            oriRecaculate.setExtendNatTax(oriRecaculate.getExtendOriTax().multiply(exchRate));

            return oriRecaculate;
        }


    }

    public void reCaculateThis(BigDecimal extendPriceQty, BigDecimal extendOriTaxPrice,BigDecimal extendOriTaxFreePrice){

        Recaculate recaculate = new Recaculate(extendPriceQty,extendOriTaxPrice,extendOriTaxFreePrice);

        Class<?> recaculateClass = recaculate.getClass();
        Field nameField = null;

        try {
            nameField = recaculateClass.getDeclaredField("extendNatTaxFreeSum");
            nameField.setAccessible(true);
            String extendNatTaxFreeSum = nameField.get(recaculate).toString();
            System.out.println("extendNatTaxFreeSum: " + extendNatTaxFreeSum);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


        System.out.println(recaculate.getExtendNatTax());
    }

  public static void main(String[] args) {
    //
      InnerClass innerClass = new InnerClass();
      innerClass.reCaculateThis(BigDecimal.ONE,BigDecimal.valueOf(15),BigDecimal.TEN);

  }
}
